package com.wiz.weixin.controllor;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wiz.weixin.manager.TencentManager;
import com.wiz.weixin.service.PrPriceService;
import com.wiz.weixin.service.StationService;
import com.wiz.weixin.to.PrPriceTO;

/**
 * 当前油价
 * @author xxy
 */
@Controller
@RequestMapping("/prPrice")
public class PrPriceControllor {
	
	@Resource
	private PrPriceService prPriceService;
	@Resource
	private StationService stationService;
	@Resource
	private TencentManager tencentManager;

	@RequestMapping(value="/list")
	public String list(HttpServletRequest request,HttpServletResponse response,
			HttpSession session, Model model) throws Exception {
		String code = request.getParameter("code");
		String openId = tencentManager.getOpenId(code);
		session.setAttribute("openid", openId);
		if(StringUtils.isBlank(openId)){
			model.addAttribute("msg", "未找到微信关联用户");
			return "/error";
		}
		//查询客户的所有会员
		List<String> hqIds = stationService.getHQIds(openId);
		if(hqIds == null || hqIds.size()<=0){
			model.addAttribute("msg", "对不起，您还未注册，请扫描加油站的二维码进行注册");
			return "/error";
		}
		Map<String,List<PrPriceTO>> map= prPriceService.listPrPrice(hqIds);
		model.addAttribute("map", map);
		return "/prPrice/price";
	}
}
